<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抽取名单</title>
</head>
<style>
    .all{
        margin: 0 auto;
        background-image: url(./名单.jpeg);
        height: 419px;
        width: 960px;
        font-size: 50px;
        text-align: center;
        display: flex;
        justify-content: space-around;
        align-items: center;
        flex-direction:column;
        color:rgb(32, 96, 215);
    }
    button{
        width: 200px;
        height: 50px;
        background-color: rgb(32, 96, 215);
        border: none;
        color: #fff;
        font-size: 30px;
        border-radius: 50px;
    }
    p{
        font-size: 30px;
        text-align: center;
        color:rgb(32, 96, 215);
        width: 900px;
        margin: 0 auto;
       
    }
</style>
<body>
    <div class="all">
        <div class="text">点击按钮开始抽取</div>
        <button>开始抽取</button>
    </div>
    <p></p>
    <script>
        let data=['王绾柚','王洛苡', '王梨珂','王梓沐', '王清一',
        '杨朝来','蒋平','唐灿华','马达','赵小雪',
    '薛文泉','丁建','凡小芬','文彭凤','王丽','王建华']
        let btn=document.querySelector('button')
        let text=document.querySelector('.text')
        let all=document.querySelector('.all')
        let p=document.querySelector('p')
        let click=0
        let timer
        let i
        btn.addEventListener('click',()=>{
            if(data.length==0){
                text.innerText='抽取完毕'
                btn.setAttribute('disabled', 'true')
                btn.style.backgroundColor='grey'
            }
            if(click%2==0 && data.length>0){
                setTimeout(()=>click++)
                timer=setInterval(()=>{
                    i=Math.floor(Math.random()*data.length)
                    text.innerText=data[i]
                    btn.innerText='停止抽取'
                },100)
            }
            if(click%2==1){
                clearInterval(timer)
                p.innerText+=data[i]+'、'
                data.splice(i,1)
                setTimeout(()=>click++)
                btn.innerText='开始抽取'
            }
        })
    </script>
</body>
</html>